<?php
echo "====\n";
$fileName = 'lock.txt';
$count = file_put_contents($fileName, time());
echo "write count:$count \n";
$lock = new \swoole_lock(SWOOLE_RWLOCK, 'lock.txt');
if($lock->lock() == true){
// if($lock->trylock() == true){
//     $lock->lock();
    
    echo "lock success!\n";
}
else{
    echo "lock error!\n";
    exit();
}
$serv = new \swoole_server("127.0.0.1", 9502);
$serv->set(array(
//     'worker_num' => 8,   //工作进程数量
//     'daemonize' => true, //是否作为守护进程
));
$serv->on('start', function ($serv){
    
    echo "start.\n";
});
$serv->on('connect', function ($serv, $fd){
    echo "Client:Connect.\n";
});
$serv->on('receive', function ($serv, $fd, $from_id, $data) {
    $serv->send($fd, 'Swoole: '.$data);
    $serv->close($fd);
});
$serv->on('close', function ($serv, $fd) {
    echo "Client: Close.\n";
});
$serv->start();
echo "server start.\n";
?>